import Vue from 'vue'
import Router from 'vue-router'
import ElementUI from 'element-ui';
import 'element-ui/lib/theme-chalk/index.css'
Vue.use(ElementUI);
Vue.use(Router)
const Login = () => require.ensure([],() => require("@/views/login"),"login")
const Home = () => require.ensure([],() => require("@/views/home"),"home")
const user = () => require.ensure([],() => require("@/views/user"),"user")
const babeil = () => require.ensure([],() => require("@/views/babeil"),"babeil")

const route =  new Router({
  routes: [
    {
      path: '/',
      name: 'home',
      component: Home,
    },
    {
      path: '/babeil',
      name: 'babeil',
      component: babeil,
    },
    {
      path: '/user',
      name: 'user',
      component: user,
    },
    {
      path: '/login',
      name: 'login',
      component: Login
    },
    {
      path: '/home',
      name: 'home',
      component: Home
    },
  ]
})
let arr = ["user"]

route.beforeEach((to,from,next)=>{
  if(arr.indexOf(to.name) !=-1){
    if(localStorage.id){
      next()
    }else{
      next("/home")
    }
  }else{
    next()
  }
})

export default  route